<?php 
/*
########################################################
#   RUTINAS DE ACCESO A LA BASE DE DATOS DEL		   #
#   MÓDULO DE CONCILIACIONES BANCARIAS				   #
#                                                      #
#   CREADOR         :    CMM                           #
#   FECHA CREACIÓN  :    19/04/2011                    #
#   PROYECTO        :    EROFLEX-CBK                   #
#                                                      #
#   V_0.2.0_20110419_0100                              #
#                                                      #
########################################################
*/
?>

<?
	require_once(dirname(dirname(__FILE__))."/connections/classSQL.php");
?>

<?php

	class classPHPLog
	{
		private $path_log;
		private $file_log;
		private $__TYPE;
		private $__TIME_SQL;
		private $__METHOD;
		private $__AMBIENTE;
		private $__USUARIO;
		private $__LOG_MSG;
		private $__DOMINIO;
		
		private $__DB_PROPERTIES;
		
		
		function  __construct($opc)
		{
			require_once(dirname(dirname(__FILE__))."/connections/classSQL.php");
			date_default_timezone_set('CLT');
			$this -> path_log			= "/u1/shares/PHPLog/cotizador/";
			$this -> file_log			= "LogCotizador.log";
			$this -> __SAVE_DB = false;
        	$this -> __SAVE_FL = false;
			
			if ($opc == 2 || $opc == 3) {
                $this -> __SAVE_DB = true;
				$this -> __DB_PROPERTIES = new classDATPHPLog();
            }
            if ($opc == 1 || $opc == 3) {
                $this -> __SAVE_FL = true;
            }
			
			
			
		}
		
		
		public function setPathLog($path)
		{
			$this -> path_log 	= $path;
		}
		
		
		public function getPathLog()
		{
			return ($this -> path_log);
		}
		
		
		public function setFileLog($file)
		{
			$this -> file_log	= $file;
		}
		
		
		public function getFileLog()
		{
			return ($this -> file_log);
		}
		
		
		
		private function SaveLog()
		{
			if ($this -> __SAVE_DB) {
				$query = "INSERT INTO log_mstr(
											    log_apl_codigo, 
											    log_tipo, 
											    log_fecha_hora, 
											    log_metodo, 
												log_ambiente,
												log_usuario,
											    log_detalle,
												log_dominio) 
				VALUES (
												1,
												\"".$this -> __TYPE."\",
												\"".$this -> __TIME_SQL."\",
												\"".$this -> __METHOD."\",
												\"".$this -> __AMBIENTE."\",
												\"".$this -> __USUARIO."\",
												\"".$this -> __LOG_MSG."\",
												\"".$this -> __DOMINIO."\"
						)";
				//echo $query;
				$connection = new classSQL(	$this -> __DB_PROPERTIES -> getHostname(), 
											$this -> __DB_PROPERTIES -> getDatabaseName(), 
											$this -> __DB_PROPERTIES -> getUserName(), 
											$this -> __DB_PROPERTIES -> getPassword());
				$connection -> exec_orden_sql($query);
				$connection -> close_connection();
			}
			
			if ($this -> __SAVE_FL) {
				$fp = fopen($this -> path_log.$this -> file_log, "a+");
				fwrite($fp, "[".$this -> __TYPE."] ".$this -> __TIME."[".$this -> __METHOD."] ".$this -> __LOG_MSG.chr(13).chr(10));
				fclose($fp);
			}
			
			
		}
		
		
		
		private function setLog($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TIME		= "[".date("D, j M Y H:i:s")."]";
			$this -> __TIME_SQL = date("Y-m-d H:i:s");
			$this -> __METHOD	= $METHOD;
			$this -> __AMBIENTE = $AMBIENTE;
			$this -> __USUARIO = $USUARIO;
			$this -> __LOG_MSG = $msg;
			$this -> __DOMINIO = $DOMINIO;
			$this -> SaveLog();
		}
		
		
		
		public function debug($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TYPE		= "DEBUG";
			$this -> setLog($msg, $METHOD, $AMBIENTE, $USUARIO, $DOMINIO);
		}
		
		
		public function info($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TYPE		= "INFO";
			$this -> setLog($msg, $METHOD, $AMBIENTE, $USUARIO, $DOMINIO);
		}
		
		
		
		public function notice($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TYPE		= "NOTICE";
			$this -> setLog($msg, $METHOD, $AMBIENTE, $USUARIO, $DOMINIO);
		}
		
		
		
		public function warning($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TYPE		= "WARNING";
			$this -> setLog($msg, $METHOD, $AMBIENTE, $USUARIO, $DOMINIO);
		}
		
		
		
		public function error($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TYPE		= "ERROR";
			$this -> setLog($msg, $METHOD, $AMBIENTE, $USUARIO, $DOMINIO);
		}
		
		
		
		public function critic($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TYPE		= "CRITIC";
			$this -> setLog($msg, $METHOD, $AMBIENTE, $USUARIO, $DOMINIO);
		}
		
		
		
		public function alert($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TYPE		= "ALERT";
			$this -> setLog($msg, $METHOD, $AMBIENTE, $USUARIO, $DOMINIO);
		}
		
		
		
		public function panic($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TYPE		= "PANIC";
			$this -> setLog($msg, $METHOD, $AMBIENTE, $USUARIO, $DOMINIO);
		}
		
		
		
		public function audit($msg, $METHOD, $AMBIENTE="", $USUARIO="", $DOMINIO="")
		{
			$this -> __TYPE		= "AUDIT";
			$this -> setLog($msg, $METHOD, $AMBIENTE, $USUARIO, $DOMINIO);
		}
	}
?>